/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.bff.engine.core.action.retrievedefault;

import static com.inspur.edp.bff.engine.core.action.BffEngineAssemblerBase.getActions;

import com.inspur.edp.bff.api.manager.context.RetrieveDefaultChildContext;
import com.inspur.edp.bff.spi.action.retrievedefault.AbstractRetrieveDefaultChildAction;
import com.inspur.edp.bff.spi.assembler.AbstractRetrieveDefaultChildAssembler;
import com.inspur.edp.formserver.viewmodel.GspViewModel;
import com.inspur.edp.formserver.viewmodel.collection.VMActionCollection;

import java.util.ArrayList;

public class BffEngineRetrieveDefaultChildAssembler extends AbstractRetrieveDefaultChildAssembler {

    private GspViewModel vo;

    private BffEngineRetrieveDefaultChildAssembler(GspViewModel vo) {
        this.vo = vo;
    }

    public static BffEngineRetrieveDefaultChildAssembler build(GspViewModel vo) {
        VMActionCollection actions = vo.getDataExtendInfo().getCreateChildActions();
        if(actions == null || actions.isEmpty()) {
            return null;
        }
        return new BffEngineRetrieveDefaultChildAssembler(vo);
    }

//    @Override
//    protected ArrayList<BeforeRetrieveDefaultAction> getBeforeRetrieveDefaultActions(RetrieveDefaultChildContext RetrieveDefaultChildContext) {
//        VMActionCollection actions = vo.getDataExtendInfo().getBeforeCreateActions();
//        return getActions(BeforeRetrieveDefaultAction.class, actions, getParamTypes(), getParamValues(RetrieveDefaultChildContext), null, null);
//    }

    @Override
    protected ArrayList<AbstractRetrieveDefaultChildAction> getRetrieveDefaultActions(RetrieveDefaultChildContext RetrieveDefaultChildContext) {
        VMActionCollection actions = vo.getDataExtendInfo().getCreateChildActions();
        return getActions(AbstractRetrieveDefaultChildAction.class, actions, getParamTypes(),
                getParamValues(RetrieveDefaultChildContext), null, "");
    }

//    @Override
//    protected ArrayList<AbstractRetrieveDefaultChildAction> getAbstractRetrieveDefaultChildActions(RetrieveDefaultChildContext RetrieveDefaultChildContext) {
//        VMActionCollection actions = vo.getDataExtendInfo().getAfterCreateActions();
//        return getActions(AbstractRetrieveDefaultChildAction.class, actions, getParamTypes(), getParamValues(RetrieveDefaultChildContext), null, null);
//    }

    private ArrayList<Class> getParamTypes() {
        ArrayList<Class> paramTypes = new ArrayList<>();
        paramTypes.add(RetrieveDefaultChildContext.class);
        return paramTypes;
    }

    private ArrayList<Object> getParamValues(RetrieveDefaultChildContext retrieveContext) {
        ArrayList<Object> values = new ArrayList<>();
        values.add(retrieveContext);
        return values;
    }
}
